package com.jake.microservice.provider.jpa.controller;

import com.jake.microservice.provider.jpa.entity.UserEntity;
import com.jake.microservice.provider.jpa.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@RequestMapping("/users")
@Slf4j
public abstract class JpaUserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public List<UserEntity> findUsers() {
        return userService.findUsers();
    }

    @GetMapping("{uid}")
    public UserEntity findUserById(@PathVariable Integer uid) {
        log.info(getClass().toString());
        return userService.findUserById(uid);
    }

    @GetMapping("query")
    public List<UserEntity> findUsersByName(String name) {
        return userService.findUsersByName(name);
    }

}
